]> git.r.bdr.sh - rbdr/map/blob - Map/Presentation/Base Components/MapRender/MapStages.swift
Map 3 first commit: files, groups and layout
[rbdr/map] / Map / Presentation / Base Components / MapRender / MapStages.swift
1 import Patterns
2 import SwiftUI
3
4 struct MapStages: View {
5
6 let mapSize: CGSize
7 let lineWidth: CGFloat
8 let stages: [CGFloat]
9 let opacity = 0.1
10
11 var body: some View {
12 ZStack(alignment: .topLeading) {
13 PatternView(
14 design: .constant(.stitch), pixelSize: 1.0, foregroundColor: .map.stageForeground,
15 backgroundColor: .map.stageBackground
16 )
17 .frame(width: w(stages[0]), height: mapSize.height)
18 PatternView(
19 design: .constant(.shingles), pixelSize: 1.0, foregroundColor: .map.stageForeground,
20 backgroundColor: .map.stageBackground
21 )
22 .offset(CGSize(width: w(stages[0]), height: 0))
23 .frame(width: w(stages[1]) - w(stages[0]), height: mapSize.height)
24 PatternView(
25 design: .constant(.shadowGrid), pixelSize: 1.0, foregroundColor: .map.stageForeground,
26 backgroundColor: .map.stageBackground
27 )
28 .offset(CGSize(width: w(stages[1]), height: 0))
29 .frame(width: w(stages[2]) - w(stages[1]), height: mapSize.height)
30 PatternView(
31 design: .constant(.wicker), pixelSize: 1.0, foregroundColor: .map.stageForeground,
32 backgroundColor: .map.stageBackground
33 )
34 .offset(CGSize(width: w(stages[2]), height: 0))
35 .frame(width: mapSize.width - w(stages[2]), height: mapSize.height)
36
37 Path { path in
38 path.move(to: CGPoint(x: w(stages[0]), y: 0))
39 path.addLine(to: CGPoint(x: w(stages[0]), y: mapSize.height))
40 path.closeSubpath()
41 path.move(to: CGPoint(x: w(stages[1]), y: 0))
42 path.addLine(to: CGPoint(x: w(stages[1]), y: mapSize.height))
43 path.closeSubpath()
44 path.move(to: CGPoint(x: w(stages[2]), y: 0))
45 path.addLine(to: CGPoint(x: w(stages[2]), y: mapSize.height))
46 path.closeSubpath()
47 path.move(to: CGPoint(x: w(stages[0]), y: 0))
48 path.closeSubpath()
49 }.strokedPath(StrokeStyle(lineWidth: lineWidth / 4, dash: [10.0, 18.0])).stroke(
50 Color.map.axisColor)
51 }
52 }
53
54 func w(_ dimension: CGFloat) -> CGFloat {
55 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
56 }
57 }
58
59 #Preview {
60 MapStages(
61 mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(0.5),
62 stages: [25.0, 50.0, 75.0])
63 }